package be.ac.ua.comp.projectGPT.players;

import be.ac.ua.comp.projectGPT.Jobs.Job;
import be.ac.ua.comp.projectGPT.Jobs.JobServer;
import be.ac.ua.comp.projectGPT.auctioneers.Auctioneer;
import be.ac.ua.comp.projectGPT.auctions.Auction;
import be.ac.ua.comp.projectGPT.exceptions.DuplicateException;
import be.ac.ua.comp.projectGPT.exceptions.InitializationException;

public class Provider extends Person {

    Auctioneer auctioneer;
    Auction auction;
    Bank bank;
    JobServer jobServer;

    public void setBank(Bank bank) {
        this.bank = bank;
        
    }

    public Provider(String name,Auction auction,Bank bank) throws InitializationException, DuplicateException {
        super(name);
        this.auction = auction;
        auction.setProvider(this);
        this.auctioneer = auction.getAuctioneer();
        this.bank = bank;
        bank.addAccount(this, Long.valueOf(0));
        this.jobServer = new JobServer();
    }

    public void stopJobs() {
        jobServer.stop();
    }

    public void setAuctioneer(Auctioneer auctioneer) {
        this.auctioneer = auctioneer;
    }

    public void setStartingBid(long bid) {
        auctioneer.setStartingBid(bid);
    }

    public void setJob(Consumer consumer,Job job) {
        logger.info("Starting job: "+job.getId()+" for consumer "+consumer.getName());
        jobServer.startJob(consumer,job);
    }

}
